package work20241224;

import java.util.concurrent.*;

/**
 * @author zdl
 * @date 2024/12/24
 */
public class Demo1 {
    public static void main(String[] args) {
        threadPool();
    }
    public static void threadPool(){
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
                5, //核心线程数
                10,        //最大线程数
                100,    //线程存活时间
                TimeUnit.SECONDS,   //存活时间单位
                new ArrayBlockingQueue<>(10),  //工作队列 有界
                Executors.defaultThreadFactory(),   //线程工厂
                new ThreadPoolExecutor.AbortPolicy() //拒绝策略
        );
        //执行任务
        for (int i = 0; i < 5; i++) {
            threadPool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("任务执行，被"+Thread.currentThread().getName()+"执行");
                }
            });
        }
    }
}
